home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_emacs.idb / usr / freeware / share / emacs / 19.34 / lisp / cal-tex.el.z / cal-tex.el (.txt)
LaTeX Document  |  1998-10-27  |  61KB  |  1,452 lines

  1. ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX.
  2. ;; Copyright (C) 1995 Free Software Foundation, Inc.
  3. ;; Author: Steve Fisk <fisk@bowdoin.edu>
  4. ;;      Edward M. Reingold <reingold@cs.uiuc.edu>
  5. ;; Keywords: calendar
  6. ;; Human-Keywords: Calendar, LaTeX
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 2, or (at your option)
  11. ;; any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  18. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. ;; Boston, MA 02111-1307, USA.
  20. ;;; Commentary:
  21. ;; This collection of functions implements the creation of LaTeX calendars
  22. ;; based on the user's holiday choices and diary file.
  23. ;; TO DO
  24. ;;     (*)  Add holidays and diary entries to daily calendar.
  25. ;;     (*)  Add diary entries to weekly calendar functions.
  26. ;;     (*)  Make calendar styles for A4 paper.
  27. ;;     (*)  Make daily and monthly styles Filofax paper.
  28. ;;     (*)  Improve the LaTeX command that produces the boxes in the monthly
  29. ;;          calendar to eliminate slight gap--what causes it?!
  30. ;;; Code:
  31. (require 'calendar)
  32. (autoload 'list-diary-entries "diary-lib" nil t)
  33. (autoload 'calendar-holiday-list "holidays" nil t)
  34. (autoload 'calendar-iso-from-absolute "cal-iso" nil t)
  35. ;;; Customizable variables 
  36. (defvar cal-tex-which-days '(0 1 2 3 4 5 6)
  37.   "*The days of the week that are displayed on the portrait monthly calendar.
  38. Sunday is 0, Monday is 1, and so on.  The default is to print from Sunday to
  39. Saturday.  For example, use
  40.                     (setq cal-tex-which-days '(1 3 5))
  41. to only print Monday, Wednesday, Friday.")
  42. (defvar cal-tex-holidays t
  43.   "*If t (default), then the holidays are also printed.
  44. If finding the holidays is too slow, set this to nil.")
  45. (defvar cal-tex-diary nil
  46.   "*If t, the diary entries are printed in the calendar.")
  47. (defvar cal-tex-daily-string
  48.   '(let* ((year (extract-calendar-year date))
  49.           (day  (calendar-day-number date))
  50.           (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
  51.      (format "%d/%d" day  days-remaining))
  52.   "*An expression in the variable `date' whose value is placed on date.
  53. The string resulting from evaluating this expression is placed at the bottom
  54. center of `date' on the monthly calendar, next to the date in the weekly
  55. calendars, and in the top center of daily calendars.
  56. Default is ordinal day number of the year and the number of days remaining.
  57. As an example of what you do, setting this to
  58.     '(progn
  59.        (require 'cal-hebrew)
  60.        (calendar-hebrew-date-string date))
  61. will put the Hebrew date at the bottom of each day.")
  62. (defvar cal-tex-buffer "calendar.tex"
  63.   "*The name for the tex-ed calendar.")
  64. (defvar cal-tex-24 nil
  65.   "*If t, use a 24 hour clock in the daily calendar.")
  66. (defvar cal-tex-daily-start 8
  67.   "*The first hour of the daily calendar page.")
  68. (defvar cal-tex-daily-end 20
  69.   "*The last hour of the daily calendar page.")
  70. ;;; Definitions for LaTeX code
  71. (defvar  cal-tex-day-prefix "\\caldate{%s}{%s}"
  72.   "The initial LaTeX code for a day.  
  73. The holidays, diary entries, bottom string, and the text follow.")
  74. (defvar cal-tex-day-name-format "\\myday{%s}%%"
  75.   "The format for LaTeX code for a day name.  The names are taken from
  76. calendar-day-name-array.")
  77. (defvar cal-tex-cal-one-month
  78. "\\def\\calmonth#1#2%
  79. {\\begin{center}%
  80. \\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
  81. \\end{center}}% 
  82. \\vspace*{-1.5cm}%
  83.   "LaTeX code for the month header")
  84. (defvar cal-tex-cal-multi-month
  85. "\\def\\calmonth#1#2#3#4%
  86. {\\begin{center}%
  87. \\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
  88. \\end{center}}% 
  89. \\vspace*{-1.5cm}%
  90.   "LaTeX code for the month header")
  91. (defvar cal-tex-myday
  92. "\\renewcommand{\\myday}[1]%
  93. {\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
  94.   "LaTeX code for a day heading")
  95. (defvar cal-tex-caldate
  96. "\\fboxsep=0pt
  97. \\long\\def\\caldate#1#2#3#4#5#6{%
  98.     \\fbox{\\hbox to\\cellwidth{%
  99.      \\vbox to\\cellheight{%
  100.        \\hbox to\\cellwidth{%
  101.           {\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
  102.           \\raisebox{\\holidaymult\\cellheight}%
  103.                    {\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
  104.        \\hbox to\\cellwidth{%
  105.            \\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
  106.        \\hspace*{1mm}%
  107.        \\hbox to\\cellwidth{#6}%
  108.        \\vfill%
  109.        \\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
  110.        \\vskip 1.4pt}%
  111.      \\hskip -0.4pt}}}
  112.   "LaTeX code to insert one box with date info in calendar.
  113. This definition is the heart of the calendar!")
  114. (defun cal-tex-list-holidays (d1 d2)
  115.   "Generate a list of all holidays from absolute date D1 to D2."
  116.   (let* ((result nil)
  117.          (start (calendar-gregorian-from-absolute d1))
  118.          (start-month (extract-calendar-month start))
  119.          (start-year (extract-calendar-year start)))
  120.     (increment-calendar-month start-month start-year 1)
  121.     (let* ((end (calendar-gregorian-from-absolute d2))
  122.            (end-month (extract-calendar-month end))
  123.            (end-year (extract-calendar-year end)))
  124.       (if (= (extract-calendar-day end) 1)
  125.           (increment-calendar-month end-month end-year -1))
  126.       (let* ((s (calendar-absolute-from-gregorian
  127.                  (list start-month 1 start-year)))
  128.              (e (calendar-absolute-from-gregorian
  129.                  (list end-month 1 end-year)))
  130.              (d s)
  131.              (never t)
  132.              (displayed-month start-month)
  133.              (displayed-year start-year))
  134.         (while (or never (<= d e))
  135.           (setq result (append result (calendar-holiday-list)))
  136.           (setq never nil)
  137.           (increment-calendar-month displayed-month displayed-year 3)
  138.           (setq d (calendar-absolute-from-gregorian
  139.                    (list displayed-month 1 displayed-year))))))
  140.     (let ((in-range)
  141.           (p result))
  142.       (while p
  143.         (and (car (car p))
  144.              (let ((a (calendar-absolute-from-gregorian (car (car p)))))
  145.                (and (<= d1 a) (<= a d2)))
  146.              (setq in-range (append (list (car p)) in-range)))
  147.         (setq p (cdr p)))
  148.       in-range)))
  149. (defun cal-tex-list-diary-entries (d1 d2)
  150.   "Generate a list of all diary-entries from absolute date D1 to D2."
  151.   (let ((diary-display-hook nil))
  152.     (list-diary-entries
  153.      (calendar-gregorian-from-absolute d1)
  154.      (1+ (- d2 d1)))))
  155. (defun cal-tex-preamble (&optional args)
  156.   "Insert the LaTeX preamble.
  157. Preamble Includes initial definitions for various LaTeX commands.
  158. Optional ARGS are included."
  159.   (set-buffer (get-buffer-create cal-tex-buffer))
  160.   (erase-buffer)
  161.   (insert "\\documentstyle")
  162.   (if args
  163.       (insert "[" args "]"))
  164.   (insert "{article}\n"
  165.           "\\hbadness 20000
  166. \\hfuzz=1000pt
  167. \\vbadness 20000
  168. \\marginparwidth 0pt
  169. \\oddsidemargin  -2cm
  170. \\evensidemargin -2cm
  171. \\marginparsep   0pt
  172. \\topmargin      0pt
  173. \\textwidth      7.5in
  174. \\textheight     9.5in
  175. \\newlength{\\cellwidth}
  176. \\newlength{\\cellheight}
  177. \\newlength{\\boxwidth}
  178. \\newlength{\\boxheight}
  179. \\newlength{\\cellsize}
  180. \\newcommand{\\myday}[1]{}
  181. \\newcommand{\\caldate}[6]{}
  182. \\newcommand{\\nocaldate}[6]{}
  183. \\newcommand{\\calsmall}[6]{}
  184. ;;;  Yearly calendars
  185. (defun cal-tex-cursor-year (&optional arg)
  186.   "Make a buffer with LaTeX commands for the year cursor is on.
  187. Optional prefix argument specifies number of years."
  188.   (interactive "P")
  189.   (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
  190.                 (if arg arg 1)))
  191. (defun cal-tex-cursor-year-landscape (&optional arg)
  192.   "Make a buffer with LaTeX commands for the year cursor is on.
  193. Optional prefix argument specifies number of years."
  194.   (interactive "P")
  195.   (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
  196.                 (if arg arg 1)
  197.                 t))
  198. (defun cal-tex-year (year n &optional landscape)
  199.   "Make a one page yearly calendar of YEAR; do this for N years.
  200. There are four rows of three months each, unless optional LANDSCAPE is t,
  201. in which case the calendar isprinted in landscape mode with three rows of
  202. four months each."
  203.   (cal-tex-insert-preamble 1 landscape "12pt")
  204.   (if landscape
  205.       (cal-tex-vspace "-.6cm")
  206.     (cal-tex-vspace "-3.1cm"))
  207.   (calendar-for-loop j from 1 to n do
  208.      (insert "\\vfill%\n")
  209.      (cal-tex-b-center)
  210.      (cal-tex-Huge (number-to-string year))
  211.      (cal-tex-e-center)
  212.      (cal-tex-vspace "1cm")
  213.      (cal-tex-b-center)
  214.      (cal-tex-b-parbox "l" (if landscape "5.9in" "4.3in"))
  215.      (insert "\n")
  216.      (cal-tex-noindent)
  217.      (cal-tex-nl)
  218.      (calendar-for-loop i from 1 to 12 do
  219.         (insert (cal-tex-mini-calendar i year "month" "1.1in" "1in"))
  220.         (insert "\\month")
  221.         (cal-tex-hspace "0.5in")
  222.         (if (zerop (mod i (if landscape 4 3)))
  223.             (cal-tex-nl "0.5in")))
  224.      (cal-tex-e-parbox)
  225.      (cal-tex-e-center)
  226.      (insert "\\vfill%\n")
  227.      (setq year (1+ year))
  228.      (if (/= j n)
  229.          (cal-tex-newpage)
  230.        (cal-tex-end-document))
  231.      (run-hooks 'cal-tex-year-hook))
  232.   (run-hooks 'cal-tex-hook))
  233. (defun cal-tex-cursor-filofax-year (&optional arg)
  234.   "Make a Filofax one page yearly calendar of year indicated by cursor.
  235. Optional parameter specifies number of years."
  236.   (interactive "P")
  237.   (let* ((n (if arg arg 1))
  238.          (year (extract-calendar-year (calendar-cursor-to-date t))))
  239.     (cal-tex-preamble "twoside")
  240.     (cal-tex-cmd "\\textwidth 3.25in")
  241.     (cal-tex-cmd "\\textheight 6.5in")
  242.     (cal-tex-cmd "\\oddsidemargin 1.675in")
  243.     (cal-tex-cmd "\\evensidemargin 1.675in")
  244.     (cal-tex-cmd "\\topmargin 0pt")
  245.     (cal-tex-cmd "\\headheight -0.875in")
  246.     (cal-tex-cmd "\\fboxsep 0.5mm")
  247.     (cal-tex-cmd "\\pagestyle{empty}")
  248.     (cal-tex-b-document)
  249.     (cal-tex-cmd "\\vspace*{0.25in}")
  250.     (calendar-for-loop j from 1 to n do
  251.        (insert (format "\\hfil {\\Large \\bf %s} \\hfil\\\\\n" year))
  252.        (cal-tex-b-center)
  253.        (cal-tex-b-parbox "l" "\\textwidth")
  254.        (insert "\n")
  255.        (cal-tex-noindent)
  256.        (cal-tex-nl)
  257.        (calendar-for-loop i from 1 to 12 do
  258.           (insert (cal-tex-mini-calendar i year
  259.                                          (calendar-month-name i)
  260.                                          "1in" ".9in" "tiny" "0.6mm")))
  261.        (insert
  262. "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
  263. \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
  264. \\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
  265. \\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
  266.        (cal-tex-e-parbox)
  267.        (cal-tex-e-center)
  268.        (setq year (1+ year))
  269.        (if (= j n)
  270.            (cal-tex-end-document)
  271.          (cal-tex-newpage)
  272.          (cal-tex-cmd "\\vspace*{0.25in}"))
  273.        (run-hooks 'cal-tex-year-hook))
  274.     (run-hooks 'cal-tex-hook)))
  275. ;;;  Monthly calendars
  276. (defun cal-tex-cursor-month-landscape (&optional arg)
  277.   "Make a buffer with LaTeX commands for the month cursor is on.
  278. Optional prefix argument specifies number of months to be produced.
  279. The output is in landscape format, one month to a page."
  280.   (interactive "P")
  281.   (let* ((n (if arg arg 1))
  282.          (date (calendar-cursor-to-date t))
  283.          (month (extract-calendar-month date))
  284.          (year (extract-calendar-year date))
  285.          (end-month month)
  286.          (end-year year)
  287.          (cal-tex-which-days '(0 1 2 3 4 5 6)))
  288.     (increment-calendar-month end-month end-year (1- n))
  289.     (let ((diary-list (if cal-tex-diary
  290.                           (cal-tex-list-diary-entries
  291.                            (calendar-absolute-from-gregorian
  292.                             (list month 1 year))
  293.                            (calendar-absolute-from-gregorian
  294.                             (list end-month
  295.                                   (calendar-last-day-of-month
  296.                                    end-month end-year)
  297.                                   end-year)))))
  298.           (holidays (if cal-tex-holidays
  299.                         (cal-tex-list-holidays
  300.                          (calendar-absolute-from-gregorian
  301.                           (list month 1 year))
  302.                          (calendar-absolute-from-gregorian
  303.                           (list end-month
  304.                                 (calendar-last-day-of-month end-month end-year)
  305.                                 end-year)))))
  306.           (other-month)
  307.           (other-year)
  308.           (small-months-at-start))
  309.       (cal-tex-insert-preamble (cal-tex-number-weeks month year 1) t "12pt")
  310.       (cal-tex-cmd cal-tex-cal-one-month)
  311.       (calendar-for-loop i from 1 to n do
  312.          (setq other-month month)
  313.          (setq other-year year)
  314.          (increment-calendar-month other-month other-year -1)
  315.          (insert (cal-tex-mini-calendar other-month other-year "lastmonth"
  316.                                         "\\cellwidth" "\\cellheight"))
  317.          (increment-calendar-month other-month other-year 2)
  318.          (insert (cal-tex-mini-calendar other-month other-year "nextmonth"
  319.                                         "\\cellwidth" "\\cellheight"))
  320.          (cal-tex-insert-month-header 1 month year month year)
  321.          (cal-tex-insert-day-names)
  322.          (cal-tex-nl ".2cm")
  323.          (setq small-months-at-start
  324.                (< 1 (mod (- (calendar-day-of-week (list month 1 year))
  325.                             calendar-week-start-day)
  326.                          7)))
  327.          (if small-months-at-start
  328.              (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
  329.          (cal-tex-insert-blank-days month year cal-tex-day-prefix)
  330.          (cal-tex-insert-days month year diary-list holidays
  331.                               cal-tex-day-prefix)
  332.          (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix)
  333.          (if (and (not small-months-at-start)
  334.                   (< 1 (mod (- (1- calendar-week-start-day)
  335.                                (calendar-day-of-week
  336.                                 (list month
  337.                                       (calendar-last-day-of-month month year)
  338.                                       year)))
  339.                                  7)))
  340.              (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
  341.                      "\\lastmonth\\nextmonth"))
  342.          (if (/= i n)
  343.              (progn
  344.                (run-hooks 'cal-tex-month-hook)
  345.                (cal-tex-newpage)
  346.                (increment-calendar-month month year 1)
  347.                (cal-tex-vspace "-2cm")
  348.                (cal-tex-insert-preamble
  349.                 (cal-tex-number-weeks month year 1) t "12pt" t))))
  350.       (cal-tex-end-document)
  351.       (run-hooks 'cal-tex-hook))))
  352. (defun cal-tex-cursor-month (arg)
  353.   "Make a buffer with LaTeX commands for the month cursor is on.
  354. Optional prefix argument specifies number of months to be produced.
  355. Calendar is condensed onto one page."
  356.   (interactive "P")
  357.   (let* ((date (calendar-cursor-to-date t))
  358.          (month (extract-calendar-month date))
  359.          (year (extract-calendar-year date))
  360.          (end-month month)
  361.          (end-year year)
  362.          (n (if arg arg 1)))
  363.     (increment-calendar-month end-month end-year (1- n))
  364.     (let ((diary-list (if cal-tex-diary
  365.                           (cal-tex-list-diary-entries
  366.                            (calendar-absolute-from-gregorian
  367.                             (list month 1 year))
  368.                            (calendar-absolute-from-gregorian
  369.                             (list end-month
  370.                                   (calendar-last-day-of-month
  371.                                    end-month end-year)
  372.                                   end-year)))))
  373.           (holidays (if cal-tex-holidays
  374.                         (cal-tex-list-holidays
  375.                          (calendar-absolute-from-gregorian
  376.                           (list month 1 year))
  377.                          (calendar-absolute-from-gregorian
  378.                           (list end-month
  379.                                 (calendar-last-day-of-month end-month end-year)
  380.                                 end-year)))))
  381.           (other-month)
  382.           (other-year))
  383.       (cal-tex-insert-preamble (cal-tex-number-weeks month year n) nil"12pt")
  384.       (if (> n 1)
  385.           (cal-tex-cmd cal-tex-cal-multi-month)
  386.         (cal-tex-cmd cal-tex-cal-one-month))
  387.       (cal-tex-insert-month-header n month year end-month end-year)
  388.       (cal-tex-insert-day-names)
  389.       (cal-tex-nl ".2cm")
  390.       (cal-tex-insert-blank-days month year cal-tex-day-prefix)
  391.       (calendar-for-loop i from 1 to n do
  392.          (setq other-month month)
  393.          (setq other-year year)
  394.          (cal-tex-insert-days month year diary-list holidays
  395.                               cal-tex-day-prefix)
  396.          (increment-calendar-month month year 1))
  397.       (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix)
  398.       (cal-tex-end-document)))
  399.   (run-hooks 'cal-tex-hook))
  400. (defun cal-tex-insert-days (month year diary-list holidays day-format) 
  401.   "Insert LaTeX commands for a range of days in monthly calendars.
  402. LaTeX commands are inserted for the days of the MONTH in YEAR.
  403. Diary entries on DIARY-LIST are included. Holidays on HOLIDAYS are included.
  404. Each day is formatted using format DAY-FORMAT."
  405.   (let* ((blank-days;; at start of month
  406.           (mod
  407.            (- (calendar-day-of-week (list month 1 year))
  408.               calendar-week-start-day)
  409.            7))
  410.          (date)
  411.          (last (calendar-last-day-of-month month year)))
  412.     (calendar-for-loop i from 1 to last do
  413.        (setq date (list month i year))
  414.        (if (memq (calendar-day-of-week date) cal-tex-which-days)
  415.            (progn 
  416.              (insert (format day-format (calendar-month-name month) i))
  417.              (cal-tex-arg (cal-tex-latexify-list diary-list date))
  418.              (cal-tex-arg (cal-tex-latexify-list holidays date))
  419.              (cal-tex-arg (eval cal-tex-daily-string))
  420.              (cal-tex-arg)
  421.              (cal-tex-comment)))
  422.        (if (and (zerop (mod (+ i blank-days) 7))
  423.                 (/= i last))
  424.            (progn
  425.              (cal-tex-hfill)
  426.              (cal-tex-nl))))))
  427. (defun cal-tex-insert-day-names ()
  428.   "Insert the names of the days at top of a monthly calendar."
  429.   (calendar-for-loop i from 0 to 6 do
  430.      (if (memq i cal-tex-which-days)
  431.          (insert (format cal-tex-day-name-format 
  432.                          (aref calendar-day-name-array 
  433.                                (mod (+ calendar-week-start-day i) 7)))))
  434.      (cal-tex-comment)))
  435. (defun cal-tex-insert-month-header (n month year end-month end-year)
  436.   "Create a title for a calendar.
  437. A title is inserted for a calendar with N months starting with 
  438. MONTH YEAR and ending with END-MONTH END-YEAR."
  439.   (let ( (month-name (calendar-month-name  month))
  440.          (end-month-name (calendar-month-name  end-month)))
  441.     (if (= 1 n)
  442.         (insert (format "\\calmonth{%s}{%s}\n\\vspace*{-0.5cm}"
  443.                 month-name year) )       
  444.         (insert (format "\\calmonth{%s}{%s}{%s}{%s}\n\\vspace*{-0.5cm}"
  445.                 month-name year end-month-name end-year))))
  446.   (cal-tex-comment))
  447. (defun cal-tex-insert-blank-days (month year day-format)
  448.   "Insert code for initial days not in calendar.
  449. Insert LaTeX code for the blank days at the beginning of the MONTH in
  450. YEAR.  The entry is formatted using DAY-FORMAT.  If the entire week is
  451. blank, no days are inserted."
  452.   (if (cal-tex-first-blank-p month year)
  453.       (let* ((blank-days;; at start of month
  454.               (mod
  455.                (- (calendar-day-of-week (list month 1 year))
  456.                   calendar-week-start-day)
  457.                7)))
  458.         (calendar-for-loop i from 0 to (1- blank-days) do 
  459.             (if (memq i cal-tex-which-days)
  460.                 (insert (format day-format " " " ") "{}{}{}{}%\n"))))))
  461. (defun cal-tex-insert-blank-days-at-end (month year day-format)
  462.   "Insert code for final days not in calendar.
  463. Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
  464. The entry is formatted using DAY-FORMAT."
  465.   (if (cal-tex-last-blank-p month year)
  466.       (let* ((last-day (calendar-last-day-of-month month year))
  467.              (blank-days;; at end of month
  468.               (mod
  469.                (- (calendar-day-of-week (list month last-day year))
  470.                   calendar-week-start-day)
  471.                7)))
  472.         (calendar-for-loop i from (1+ blank-days) to 6 do 
  473.            (if (memq i cal-tex-which-days)
  474.                (insert (format day-format "" "") "{}{}{}{}%\n"))))))
  475. (defun cal-tex-first-blank-p (month year)
  476.   "Determine if any days of the first week will be printed.
  477. Return t if there will there be any days of the first week printed
  478. in the calendar starting in MONTH YEAR."
  479.   (let ((any-days nil)
  480.         (the-saturday))                 ;the day of week of 1st Saturday
  481.     (calendar-for-loop i from 1 to 7 do
  482.        (if (= 6 (calendar-day-of-week (list month i year)))
  483.            (setq the-saturday i)))
  484.     (calendar-for-loop i from 1 to the-saturday do
  485.        (if (memq (calendar-day-of-week (list month i year))
  486.                  cal-tex-which-days)
  487.            (setq any-days t)))
  488.     any-days))
  489. (defun cal-tex-last-blank-p (month year)
  490.   "Determine if any days of the last week will be printed.
  491. Return t if there will there be any days of the last week printed
  492. in the calendar starting in MONTH YEAR."
  493.   (let ((any-days nil)
  494.         (last-day (calendar-last-day-of-month month year))
  495.         (the-sunday))                   ;the day of week of last Sunday
  496.     (calendar-for-loop i from (- last-day 6) to last-day do
  497.        (if (= 0 (calendar-day-of-week (list month i year)))
  498.            (setq the-sunday i)))
  499.     (calendar-for-loop i from the-sunday to last-day do
  500.        (if (memq (calendar-day-of-week (list month i year))
  501.                  cal-tex-which-days)
  502.            (setq any-days t)))
  503.     any-days))
  504. (defun cal-tex-number-weeks (month year n)
  505.   "Determine the number of weeks in a range of dates.
  506. Compute the number of  weeks in the calendar starting with MONTH and YEAR, 
  507. and lasting N months, including only the days in WHICH-DAYS. As it stands, 
  508. this is only an upper bound."
  509.   (let ((d (list month 1 year)))
  510.     (increment-calendar-month month year (1- n))
  511.     (/ (- (calendar-dayname-on-or-before
  512.            calendar-week-start-day
  513.            (+ 7 (calendar-absolute-from-gregorian
  514.                    (list month (calendar-last-day-of-month month year) year))))
  515.           (calendar-dayname-on-or-before
  516.            calendar-week-start-day
  517.            (calendar-absolute-from-gregorian d)))
  518.        7)))
  519. ;;; Weekly calendars
  520. (defun cal-tex-cursor-week (&optional arg)
  521.   "Make a buffer with LaTeX commands for a two-page one-week calendar.
  522. It applies to the week that point is in.
  523. Optional prefix argument specifies number of weeks.
  524. Holidays are included if `cal-tex-holidays' is t."
  525.   (interactive "P")
  526.   (let* ((n (if arg arg 1))
  527.          (date (calendar-gregorian-from-absolute
  528.                 (calendar-dayname-on-or-before
  529.                  calendar-week-start-day
  530.                  (calendar-absolute-from-gregorian
  531.                   (calendar-cursor-to-date t)))))
  532.          (month (extract-calendar-month date))
  533.          (year (extract-calendar-year date))
  534.          (holidays (if cal-tex-holidays
  535.                        (cal-tex-list-holidays
  536.                         (calendar-absolute-from-gregorian date)
  537.                         (+ (* 7 n)
  538.                            (calendar-absolute-from-gregorian date))))))
  539.     (cal-tex-preamble "11pt")
  540.     (cal-tex-cmd "\\textwidth   6.5in")
  541.     (cal-tex-cmd "\\textheight 10.5in")
  542.     (cal-tex-cmd "\\oddsidemargin 0in")
  543.     (cal-tex-cmd "\\evensidemargin 0in")
  544.     (insert cal-tex-LaTeX-hourbox)
  545.     (cal-tex-b-document)
  546.     (cal-tex-cmd "\\pagestyle{empty}")
  547.     (calendar-for-loop i from 1 to n do
  548.        (cal-tex-vspace "-1.5in")
  549.        (cal-tex-b-center)
  550.        (cal-tex-Huge-bf (format "\\uppercase{%s}"
  551.                                 (calendar-month-name month)))
  552.        (cal-tex-hspace "2em")
  553.        (cal-tex-Huge-bf (number-to-string year))
  554.        (cal-tex-nl ".5cm")
  555.        (cal-tex-e-center)
  556.        (cal-tex-hspace "-.2in")
  557.        (cal-tex-b-parbox "l" "7in")
  558.        (calendar-for-loop j from 1 to 7 do 
  559.           (cal-tex-week-hours date holidays "3.1")
  560.           (setq date (cal-tex-incr-date date)))
  561.        (cal-tex-e-parbox)
  562.        (setq month (extract-calendar-month date))
  563.        (setq year (extract-calendar-year date))
  564.        (if (/= i n)
  565.            (progn
  566.              (run-hooks 'cal-tex-week-hook)
  567.              (cal-tex-newpage))))
  568.     (cal-tex-end-document)
  569.     (run-hooks 'cal-tex-hook)))
  570. (defun cal-tex-cursor-week2 (&optional arg)
  571.   "Make a buffer with LaTeX commands for a two-page one-week calendar.
  572. It applies to the week that point is in.
  573. Optional prefix argument specifies number of weeks.
  574. Holidays are included if `cal-tex-holidays' is t."
  575.   (interactive "P")
  576.   (let* ((n (if arg arg 1))
  577.          (date (calendar-gregorian-from-absolute
  578.                 (calendar-dayname-on-or-before
  579.                  calendar-week-start-day
  580.                  (calendar-absolute-from-gregorian
  581.                   (calendar-cursor-to-date t)))))
  582.          (month (extract-calendar-month date))
  583.          (year (extract-calendar-year date))
  584.          (d date)
  585.          (holidays (if cal-tex-holidays
  586.                        (cal-tex-list-holidays
  587.                         (calendar-absolute-from-gregorian date)
  588.                         (+ (* 7 n)
  589.                            (calendar-absolute-from-gregorian date))))))
  590.     (cal-tex-preamble "12pt")
  591.     (cal-tex-cmd "\\textwidth   6.5in")
  592.     (cal-tex-cmd "\\textheight 10.5in")
  593.     (cal-tex-cmd "\\oddsidemargin 0in")
  594.     (cal-tex-cmd "\\evensidemargin 0in")
  595.     (insert cal-tex-LaTeX-hourbox)
  596.     (cal-tex-b-document)
  597.     (cal-tex-cmd "\\pagestyle{empty}")
  598.     (calendar-for-loop i from 1 to n do
  599.        (cal-tex-vspace "-1.5in")
  600.        (cal-tex-b-center)
  601.        (cal-tex-Huge-bf (format "\\uppercase{%s}"
  602.                                 (calendar-month-name month)))
  603.        (cal-tex-hspace "2em")
  604.        (cal-tex-Huge-bf (number-to-string year))
  605.        (cal-tex-nl ".5cm")
  606.        (cal-tex-e-center)
  607.        (cal-tex-hspace "-.2in")
  608.        (cal-tex-b-parbox "l" "\\textwidth")
  609.        (calendar-for-loop j from 1 to 3 do 
  610.           (cal-tex-week-hours date holidays "5")
  611.           (setq date (cal-tex-incr-date date)))
  612.        (cal-tex-e-parbox)
  613.        (cal-tex-nl)
  614.        (insert (cal-tex-mini-calendar
  615.                 (extract-calendar-month (cal-tex-previous-month date))
  616.                 (extract-calendar-year (cal-tex-previous-month date))
  617.                 "lastmonth" "1.1in" "1in"))
  618.        (insert (cal-tex-mini-calendar
  619.                 (extract-calendar-month date)
  620.                 (extract-calendar-year date)
  621.                 "thismonth" "1.1in" "1in"))
  622.        (insert (cal-tex-mini-calendar
  623.                 (extract-calendar-month (cal-tex-next-month date))
  624.                 (extract-calendar-year (cal-tex-next-month date))
  625.                 "nextmonth" "1.1in" "1in"))
  626.        (insert "\\hbox to \\textwidth{")
  627.        (cal-tex-hfill)
  628.        (insert "\\lastmonth")
  629.        (cal-tex-hfill)
  630.        (insert "\\thismonth")
  631.        (cal-tex-hfill)
  632.        (insert "\\nextmonth")
  633.        (cal-tex-hfill)
  634.        (insert "}")
  635.        (cal-tex-nl)
  636.        (cal-tex-b-parbox "l" "\\textwidth")
  637.        (calendar-for-loop j from 4 to 7 do 
  638.                           (cal-tex-week-hours date holidays "5")
  639.                           (setq date (cal-tex-incr-date date)))
  640.        (cal-tex-e-parbox)
  641.        (setq month (extract-calendar-month date))
  642.        (setq year (extract-calendar-year date))
  643.        (if (/= i n)
  644.            (progn
  645.              (run-hooks 'cal-tex-week-hook)
  646.              (cal-tex-newpage))))
  647.     (cal-tex-end-document)
  648.     (run-hooks 'cal-tex-hook)))
  649. (defun cal-tex-cursor-week-iso (&optional arg)
  650.   "Make a buffer with LaTeX commands for a one page ISO-style weekly calendar.
  651. Optional prefix argument specifies number of weeks.
  652. Diary entries are included if `cal-tex-diary' is t.
  653. Holidays are included if `cal-tex-holidays' is t."
  654.   (interactive "P")
  655.   (let* ((n (if arg arg 1))
  656.          (date (calendar-gregorian-from-absolute
  657.                 (calendar-dayname-on-or-before
  658.                  1
  659.                  (calendar-absolute-from-gregorian
  660.                   (calendar-cursor-to-date t)))))
  661.          (month (extract-calendar-month date))
  662.          (year (extract-calendar-year date))
  663.          (day (extract-calendar-day date))
  664.          (holidays (if cal-tex-holidays
  665.                        (cal-tex-list-holidays
  666.                         (calendar-absolute-from-gregorian date)
  667.                         (+ (* 7 n)
  668.                            (calendar-absolute-from-gregorian date)))))
  669.          (diary-list (if cal-tex-diary
  670.                          (cal-tex-list-diary-entries
  671.                           (calendar-absolute-from-gregorian
  672.                            (list month 1 year))
  673.                         (+ (* 7 n)
  674.                            (calendar-absolute-from-gregorian date))))))
  675.     (cal-tex-preamble "11pt")
  676.     (cal-tex-cmd "\\textwidth 6.5in")
  677.     (cal-tex-cmd "\\textheight 10.5in")
  678.     (cal-tex-cmd "\\oddsidemargin 0in")
  679.     (cal-tex-cmd "\\evensidemargin 0in")
  680.     (cal-tex-b-document)
  681.     (cal-tex-cmd "\\pagestyle{empty}")
  682.     (calendar-for-loop i from 1 to n do
  683.        (cal-tex-vspace "-1.5in")
  684.        (cal-tex-b-center)
  685.        (cal-tex-Huge-bf
  686.         (let* ((d (calendar-iso-from-absolute
  687.                    (calendar-absolute-from-gregorian date))))
  688.           (format "Week %d of %d"
  689.                   (extract-calendar-month d)
  690.                   (extract-calendar-year d))))
  691.        (cal-tex-nl ".5cm")
  692.        (cal-tex-e-center)
  693.        (cal-tex-b-parbox "l" "\\textwidth")
  694.        (calendar-for-loop j from 1 to 7 do 
  695.           (cal-tex-b-parbox "t" "\\textwidth")
  696.           (cal-tex-b-parbox "t" "\\textwidth")
  697.           (cal-tex-rule "0pt" "\\textwidth" ".2mm")
  698.           (cal-tex-nl)
  699.           (cal-tex-b-parbox "t" "\\textwidth")
  700.           (cal-tex-large-bf (calendar-day-name date))
  701.           (insert ", ")
  702.           (cal-tex-large-bf (calendar-month-name month))
  703.           (insert " ")
  704.           (cal-tex-large-bf (number-to-string day))
  705.           (if (not (string= "" (cal-tex-latexify-list holidays date)))
  706.               (progn
  707.                 (insert ": ")
  708.                 (cal-tex-large-bf (cal-tex-latexify-list holidays date "; "))))
  709.           (cal-tex-hfill)
  710.           (insert " " (eval cal-tex-daily-string))
  711.           (cal-tex-e-parbox)
  712.           (cal-tex-nl)
  713.           (cal-tex-noindent)
  714.           (cal-tex-b-parbox "t" "\\textwidth")
  715.           (if (not (string= "" (cal-tex-latexify-list diary-list date)))
  716.               (progn
  717.                 (insert "\\vbox to 0pt{")
  718.                 (cal-tex-large-bf
  719.                  (cal-tex-latexify-list diary-list date))
  720.                 (insert "}")))
  721.           (cal-tex-e-parbox)
  722.           (cal-tex-nl)
  723.           (setq date (cal-tex-incr-date date))
  724.           (setq month (extract-calendar-month date))
  725.           (setq day (extract-calendar-day date))
  726.           (cal-tex-e-parbox)
  727.           (cal-tex-e-parbox "2cm")
  728.           (cal-tex-nl)
  729.           (setq month (extract-calendar-month date))
  730.           (setq year (extract-calendar-year date)))
  731.        (cal-tex-e-parbox)% 
  732.        (if (/= i n)
  733.            (progn
  734.              (run-hooks 'cal-tex-week-hook)
  735.              (cal-tex-newpage))))
  736.     (cal-tex-end-document)
  737.     (run-hooks 'cal-tex-hook)))
  738. (defvar cal-tex-LaTeX-hourbox 
  739.   "\\newcommand{\\hourbox}[2]%
  740. {\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
  741.   "One hour and a line on the right.")
  742. (defun cal-tex-week-hours (date holidays height)
  743.   "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT." 
  744.   (let ((month (extract-calendar-month date))
  745.         (day   (extract-calendar-day date))
  746.         (year  (extract-calendar-year date))
  747.         (afternoon))
  748.   (cal-tex-comment "begin cal-tex-week-hours")
  749.   (cal-tex-cmd  "\\ \\\\[-.2cm]")
  750.   (cal-tex-cmd "\\noindent")
  751.   (cal-tex-b-parbox "l" "6.8in")
  752.   (cal-tex-large-bf (calendar-day-name date))
  753.   (insert ", ")
  754.   (cal-tex-large-bf (calendar-month-name month))
  755.   (insert " ")
  756.   (cal-tex-large-bf (number-to-string day))
  757.   (if (not (string= "" (cal-tex-latexify-list holidays date)))
  758.       (progn
  759.         (insert ": ")
  760.         (cal-tex-large-bf (cal-tex-latexify-list holidays date "; "))))
  761.   (cal-tex-hfill)
  762.   (insert " " (eval cal-tex-daily-string))
  763.   (cal-tex-e-parbox)
  764.   (cal-tex-nl "-.3cm")
  765.   (cal-tex-rule "0pt" "6.8in" ".2mm")
  766.   (cal-tex-nl "-.1cm")
  767.   (calendar-for-loop i from 8 to 12 do
  768.      (if cal-tex-24
  769.          (setq afternoon (+ i 5))
  770.        (setq afternoon (- i 7)))
  771.      (cal-tex-cmd "\\hourbox"  (number-to-string i))
  772.      (cal-tex-arg height)
  773.      (cal-tex-hspace ".4cm")
  774.      (cal-tex-cmd "\\hourbox"  (number-to-string afternoon))
  775.      (cal-tex-arg height)
  776.      (cal-tex-nl))))
  777. (defun cal-tex-cursor-week-monday (&optional arg)
  778.   "Make a buffer with LaTeX commands for a two-page one-week calendar.
  779. It applies to the week that point is in, and starts on Monday.
  780. Optional prefix argument specifies number of weeks.
  781. Holidays are included if `cal-tex-holidays' is t."
  782.   (interactive "P")
  783.   (let* ((n (if arg arg 1))
  784.          (date (calendar-gregorian-from-absolute
  785.                 (calendar-dayname-on-or-before
  786.                  0
  787.                  (calendar-absolute-from-gregorian
  788.                   (calendar-cursor-to-date t))))))
  789.     (cal-tex-preamble "11pt")
  790.     (cal-tex-cmd "\\textwidth   6.5in")
  791.     (cal-tex-cmd "\\textheight 10.5in")
  792.     (cal-tex-cmd "\\oddsidemargin 0in")
  793.     (cal-tex-cmd "\\evensidemargin 0in")
  794.     (cal-tex-b-document)
  795.     (calendar-for-loop i from 1 to n do
  796.        (cal-tex-vspace "-1cm")
  797.        (insert "\\noindent ")
  798.        (cal-tex-weekly4-box (cal-tex-incr-date date) nil)
  799.        (cal-tex-weekly4-box (cal-tex-incr-date date 4) nil)
  800.        (cal-tex-nl ".2cm")
  801.        (cal-tex-weekly4-box (cal-tex-incr-date date 2) nil)
  802.        (cal-tex-weekly4-box (cal-tex-incr-date date 5) nil)
  803.        (cal-tex-nl ".2cm")
  804.        (cal-tex-weekly4-box (cal-tex-incr-date date 3) nil)
  805.        (cal-tex-weekly4-box (cal-tex-incr-date date 6) t)
  806.        (if (/= i n)
  807.            (progn
  808.              (run-hooks 'cal-tex-week-hook)
  809.          (setq date (cal-tex-incr-date date 7))
  810.              (cal-tex-newpage))))
  811.     (cal-tex-end-document)
  812.     (run-hooks 'cal-tex-hook)))
  813. (defun cal-tex-weekly4-box (date weekend)
  814.   "Make one box for DATE, different if WEEKEND."
  815.   (let* (
  816.     (day (extract-calendar-day date))
  817.     (month (extract-calendar-month date))
  818.     (year (extract-calendar-year date))
  819.     (dayname (calendar-day-name date))
  820.     (date1 (cal-tex-incr-date date))
  821.     (day1 (extract-calendar-day date1))
  822.     (month1 (extract-calendar-month date1))
  823.     (year1 (extract-calendar-year date1))
  824.     (dayname1 (calendar-day-name date1))
  825.     (cal-tex-b-framebox "8cm" "l")
  826.     (cal-tex-b-parbox "b" "7.5cm")
  827.     (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n" dayname month day year))
  828.     (cal-tex-rule "0pt" "7.5cm" ".5mm")
  829.     (cal-tex-nl)
  830.     (if (not weekend)
  831.     (progn
  832.       (calendar-for-loop i from 8 to 12 do
  833.          (insert (format "{\\large\\sf %d}\\\\\n" i)))
  834.       (calendar-for-loop i from 1 to 5 do
  835.          (insert (format "{\\large\\sf %d}\\\\\n" i)))))
  836.     (cal-tex-nl ".5cm")
  837.     (if weekend
  838.     (progn
  839.       (cal-tex-vspace "1cm")
  840.       (insert "\\ \\vfill")
  841.       (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n" 
  842.               dayname1 month1 day1 year1))
  843.       (cal-tex-rule "0pt" "7.5cm" ".5mm")
  844.       (cal-tex-nl "1.5cm")
  845.       (cal-tex-vspace "1cm")))
  846.      (cal-tex-e-parbox)
  847.      (cal-tex-e-framebox)
  848.      (cal-tex-hspace "1cm")))
  849. (defun cal-tex-cursor-filofax-2week (&optional arg)
  850.   "Two-weeks-at-a-glance Filofax style calendar for week indicated by cursor.
  851. Optional prefix argument specifies number of weeks.
  852. Diary entries are included if `cal-tex-diary' is t.
  853. Holidays are included if `cal-tex-holidays' is t."
  854.   (interactive "P")
  855.   (let* ((n (if arg arg 1))
  856.          (date (calendar-gregorian-from-absolute
  857.                 (calendar-dayname-on-or-before
  858.                  calendar-week-start-day
  859.                  (calendar-absolute-from-gregorian
  860.                   (calendar-cursor-to-date t)))))
  861.          (month (extract-calendar-month date))
  862.          (year (extract-calendar-year date))
  863.          (day (extract-calendar-day date))
  864.          (holidays (if cal-tex-holidays
  865.                        (cal-tex-list-holidays
  866.                         (calendar-absolute-from-gregorian date)
  867.                         (+ (* 7 n)
  868.                            (calendar-absolute-from-gregorian date)))))
  869.          (diary-list (if cal-tex-diary
  870.                          (cal-tex-list-diary-entries
  871.                           (calendar-absolute-from-gregorian
  872.                            (list month 1 year))
  873.                         (+ (* 7 n)
  874.                            (calendar-absolute-from-gregorian date))))))
  875.     (cal-tex-preamble "twoside")
  876.     (cal-tex-cmd "\\textwidth 3.25in")
  877.     (cal-tex-cmd "\\textheight 6.5in")
  878.     (cal-tex-cmd "\\oddsidemargin 1.75in")
  879.     (cal-tex-cmd "\\evensidemargin 1.5in")
  880.     (cal-tex-cmd "\\topmargin 0pt")
  881.     (cal-tex-cmd "\\headheight -0.875in")
  882.     (cal-tex-cmd "\\headsep 0.125in")
  883.     (cal-tex-cmd "\\footskip .125in")
  884.     (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
  885. \\long\\def\\rightday#1#2#3#4#5{%
  886.    \\rule{\\textwidth}{0.3pt}\\\\%
  887.    \\hbox to \\textwidth{%
  888.      \\vbox to 0.7in{%
  889.           \\vspace*{2pt}%
  890.           \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
  891.           \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
  892.           \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
  893. \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
  894. \\long\\def\\leftday#1#2#3#4#5{%
  895.    \\rule{\\textwidth}{0.3pt}\\\\%
  896.    \\hbox to \\textwidth{%
  897.      \\vbox to 0.7in{%
  898.           \\vspace*{2pt}%
  899.           \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
  900.           \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
  901.           \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
  902.     (cal-tex-b-document)
  903.     (cal-tex-cmd "\\pagestyle{empty}")
  904.     (calendar-for-loop i from 1 to n do
  905.        (if (= (mod i 2) 1)
  906.            (insert "\\righthead")
  907.          (insert "\\lefthead"))
  908.        (cal-tex-arg
  909.         (let ((d (cal-tex-incr-date date 6)))
  910.           (if (= (extract-calendar-month date)
  911.                  (extract-calendar-month d))
  912.               (format "%s %s"
  913.                       (calendar-month-name
  914.                        (extract-calendar-month date))
  915.                       (extract-calendar-year date))
  916.             (if (=  (extract-calendar-year date)
  917.                     (extract-calendar-year d))
  918.                 (format "%s---%s %s"
  919.                         (calendar-month-name
  920.                          (extract-calendar-month date))
  921.                         (calendar-month-name
  922.                          (extract-calendar-month d))
  923.                         (extract-calendar-year date))
  924.               (format "%s %s---%s %s"
  925.                       (calendar-month-name
  926.                        (extract-calendar-month date))
  927.                       (extract-calendar-year date)
  928.                       (calendar-month-name (extract-calendar-month d))
  929.                       (extract-calendar-year d))))))
  930.        (insert "%\n")
  931.        (calendar-for-loop j from 1 to 7 do 
  932.           (if (= (mod i 2) 1)
  933.               (insert "\\rightday")
  934.             (insert "\\leftday"))
  935.           (cal-tex-arg (calendar-day-name date))
  936.           (cal-tex-arg (int-to-string (extract-calendar-day date)))
  937.           (cal-tex-arg (cal-tex-latexify-list diary-list date))
  938.           (cal-tex-arg (cal-tex-latexify-list holidays date))
  939.           (cal-tex-arg (eval cal-tex-daily-string))
  940.           (insert "%\n")
  941.           (setq date (cal-tex-incr-date date)))
  942.        (if (/= i n)
  943.            (progn
  944.              (run-hooks 'cal-tex-week-hook)
  945.              (cal-tex-newpage))))
  946.     (cal-tex-end-document)
  947.     (run-hooks 'cal-tex-hook)))
  948. (defun cal-tex-cursor-filofax-week (&optional arg)
  949.   "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
  950. Optional prefix argument specifies number of weeks.
  951. Weeks start on Monday. 
  952. Diary entries are included if `cal-tex-diary' is t.
  953. Holidays are included if `cal-tex-holidays' is t."
  954.   (interactive "P")
  955.   (let* ((n (if arg arg 1))
  956.          (date (calendar-gregorian-from-absolute
  957.                 (calendar-dayname-on-or-before
  958.                  1
  959.                  (calendar-absolute-from-gregorian
  960.                   (calendar-cursor-to-date t)))))
  961.          (month (extract-calendar-month date))
  962.          (year (extract-calendar-year date))
  963.          (day (extract-calendar-day date))
  964.          (holidays (if cal-tex-holidays
  965.                        (cal-tex-list-holidays
  966.                         (calendar-absolute-from-gregorian date)
  967.                         (+ (* 7 n)
  968.                            (calendar-absolute-from-gregorian date)))))
  969.          (diary-list (if cal-tex-diary
  970.                          (cal-tex-list-diary-entries
  971.                           (calendar-absolute-from-gregorian
  972.                            (list month 1 year))
  973.                         (+ (* 7 n)
  974.                            (calendar-absolute-from-gregorian date))))))
  975.     (cal-tex-preamble "twoside")
  976.     (cal-tex-cmd "\\textwidth 3.25in")
  977.     (cal-tex-cmd "\\textheight 6.5in")
  978.     (cal-tex-cmd "\\oddsidemargin 1.75in")
  979.     (cal-tex-cmd "\\evensidemargin 1.5in")
  980.     (cal-tex-cmd "\\topmargin 0pt")
  981.     (cal-tex-cmd "\\headheight -0.875in")
  982.     (cal-tex-cmd "\\headsep 0.125in")
  983.     (cal-tex-cmd "\\footskip .125in")
  984.     (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
  985. \\long\\def\\rightday#1#2#3#4#5{%
  986.    \\rule{\\textwidth}{0.3pt}\\\\%
  987.    \\hbox to \\textwidth{%
  988.      \\vbox to 1.85in{%
  989.           \\vspace*{2pt}%
  990.           \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
  991.           \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
  992.           \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
  993. \\long\\def\\weekend#1#2#3#4#5{%
  994.    \\rule{\\textwidth}{0.3pt}\\\\%
  995.    \\hbox to \\textwidth{%
  996.      \\vbox to .8in{%
  997.           \\vspace*{2pt}%
  998.           \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
  999.           \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
  1000.           \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
  1001. \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
  1002. \\long\\def\\leftday#1#2#3#4#5{%
  1003.    \\rule{\\textwidth}{0.3pt}\\\\%
  1004.    \\hbox to \\textwidth{%
  1005.      \\vbox to 1.85in{%
  1006.           \\vspace*{2pt}%
  1007.           \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
  1008.           \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
  1009.           \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
  1010.     (cal-tex-b-document)
  1011.     (cal-tex-cmd "\\pagestyle{empty}\\ ")
  1012.     (cal-tex-newpage)
  1013.     (calendar-for-loop i from 1 to n do
  1014.        (insert "\\lefthead")
  1015.        (cal-tex-arg
  1016.         (let ((d (cal-tex-incr-date date 2)))
  1017.           (if (= (extract-calendar-month date)
  1018.                  (extract-calendar-month d))
  1019.               (format "%s %s"
  1020.                       (calendar-month-name
  1021.                        (extract-calendar-month date))
  1022.                       (extract-calendar-year date))
  1023.             (if (=  (extract-calendar-year date)
  1024.                     (extract-calendar-year d))
  1025.                 (format "%s---%s %s"
  1026.                         (calendar-month-name
  1027.                          (extract-calendar-month date))
  1028.                         (calendar-month-name
  1029.                          (extract-calendar-month d))
  1030.                         (extract-calendar-year date))
  1031.               (format "%s %s---%s %s"
  1032.                       (calendar-month-name
  1033.                        (extract-calendar-month date))
  1034.                       (extract-calendar-year date)
  1035.                       (calendar-month-name (extract-calendar-month d))
  1036.                       (extract-calendar-year d))))))
  1037.        (insert "%\n")
  1038.        (calendar-for-loop j from 1 to 3 do 
  1039.           (insert "\\leftday")
  1040.           (cal-tex-arg (calendar-day-name date))
  1041.           (cal-tex-arg (int-to-string (extract-calendar-day date)))
  1042.           (cal-tex-arg (cal-tex-latexify-list diary-list date))
  1043.           (cal-tex-arg (cal-tex-latexify-list holidays date))
  1044.           (cal-tex-arg (eval cal-tex-daily-string))
  1045.           (insert "%\n")
  1046.           (setq date (cal-tex-incr-date date)))
  1047.        (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
  1048.        (cal-tex-newpage)
  1049.        (insert "\\righthead")
  1050.        (cal-tex-arg
  1051.         (let ((d (cal-tex-incr-date date 3)))
  1052.           (if (= (extract-calendar-month date)
  1053.                  (extract-calendar-month d))
  1054.               (format "%s %s"
  1055.                       (calendar-month-name
  1056.                        (extract-calendar-month date))
  1057.                       (extract-calendar-year date))
  1058.             (if (=  (extract-calendar-year date)
  1059.                     (extract-calendar-year d))
  1060.                 (format "%s---%s %s"
  1061.                         (calendar-month-name
  1062.                          (extract-calendar-month date))
  1063.                         (calendar-month-name
  1064.                          (extract-calendar-month d))
  1065.                         (extract-calendar-year date))
  1066.               (format "%s %s---%s %s"
  1067.                       (calendar-month-name
  1068.                        (extract-calendar-month date))
  1069.                       (extract-calendar-year date)
  1070.                       (calendar-month-name (extract-calendar-month d))
  1071.                       (extract-calendar-year d))))))
  1072.        (insert "%\n")
  1073.        (calendar-for-loop j from 1 to 2 do 
  1074.           (insert "\\rightday")
  1075.           (cal-tex-arg (calendar-day-name date))
  1076.           (cal-tex-arg (int-to-string (extract-calendar-day date)))
  1077.           (cal-tex-arg (cal-tex-latexify-list diary-list date))
  1078.           (cal-tex-arg (cal-tex-latexify-list holidays date))
  1079.           (cal-tex-arg (eval cal-tex-daily-string))
  1080.           (insert "%\n")
  1081.           (setq date (cal-tex-incr-date date)))
  1082.        (calendar-for-loop j from 1 to 2 do 
  1083.           (insert "\\weekend")
  1084.           (cal-tex-arg (calendar-day-name date))
  1085.           (cal-tex-arg (int-to-string (extract-calendar-day date)))
  1086.           (cal-tex-arg (cal-tex-latexify-list diary-list date))
  1087.           (cal-tex-arg (cal-tex-latexify-list holidays date))
  1088.           (cal-tex-arg (eval cal-tex-daily-string))
  1089.           (insert "%\n")
  1090.           (setq date (cal-tex-incr-date date)))
  1091.        (if (/= i n)
  1092.            (progn
  1093.              (run-hooks 'cal-tex-week-hook)
  1094.              (cal-tex-newpage))))
  1095.     (cal-tex-end-document)
  1096.     (run-hooks 'cal-tex-hook)))
  1097. ;;;  Daily calendars
  1098. (defun cal-tex-cursor-day (&optional arg)
  1099.   "Make a buffer with LaTeX commands for the day cursor is on.
  1100. Optional prefix argument specifies number of days."
  1101.   (interactive "P")
  1102.   (let ((n (if arg arg 1))
  1103.         (date (calendar-absolute-from-gregorian (calendar-cursor-to-date t))))
  1104.     (cal-tex-preamble "12pt")
  1105.     (cal-tex-cmd "\\textwidth       6.5in")
  1106.     (cal-tex-cmd "\\textheight 10.5in")
  1107.     (cal-tex-b-document)
  1108.     (cal-tex-cmd "\\pagestyle{empty}")
  1109.     (calendar-for-loop i from 1 to n do
  1110.        (cal-tex-vspace "-1.7in")
  1111.        (cal-tex-daily-page (calendar-gregorian-from-absolute date))
  1112.        (setq date (1+ date))
  1113.        (if (/= i n)
  1114.           (progn
  1115.             (cal-tex-newpage)
  1116.             (run-hooks 'cal-tex-daily-hook))))
  1117.     (cal-tex-end-document)
  1118.     (run-hooks 'cal-tex-hook)))
  1119. (defun cal-tex-daily-page (date)
  1120.   "Make a calendar page for Gregorian DATE on 8.5 by 11 paper."
  1121.   (let* ((hour)
  1122.          (month-name (calendar-month-name (extract-calendar-month date))))
  1123.     (cal-tex-banner "cal-tex-daily-page")
  1124.     (cal-tex-b-makebox "4cm" "l")
  1125.     (cal-tex-b-parbox "b" "3.8cm")
  1126.     (cal-tex-rule "0mm" "0mm" "2cm")
  1127.     (cal-tex-Huge (number-to-string (extract-calendar-day date)))
  1128.     (cal-tex-nl ".5cm")
  1129.     (cal-tex-bf month-name )
  1130.     (cal-tex-e-parbox)
  1131.     (cal-tex-hspace "1cm")
  1132.     (cal-tex-scriptsize (eval cal-tex-daily-string))
  1133.     (cal-tex-hspace "3.5cm")
  1134.     (cal-tex-e-makebox)
  1135.     (cal-tex-hfill)
  1136.     (cal-tex-b-makebox "4cm" "r")
  1137.     (cal-tex-bf (calendar-day-name date))
  1138.     (cal-tex-e-makebox)
  1139.     (cal-tex-nl)
  1140.     (cal-tex-hspace ".4cm")
  1141.     (cal-tex-rule "0mm" "16.1cm" "1mm")
  1142.     (cal-tex-nl ".1cm")
  1143.     (calendar-for-loop i from cal-tex-daily-start to cal-tex-daily-end do
  1144.        (cal-tex-cmd "\\noindent")
  1145.        (setq hour (if cal-tex-24
  1146.                       i
  1147.                     (mod i 12)))
  1148.        (if (= 0 hour) (setq hour 12))
  1149.        (cal-tex-b-makebox "1cm" "c")
  1150.        (cal-tex-arg (number-to-string hour))
  1151.        (cal-tex-e-makebox)
  1152.        (cal-tex-rule "0mm" "15.5cm" ".2mm")
  1153.        (cal-tex-nl ".2cm")
  1154.        (cal-tex-b-makebox "1cm" "c")
  1155.        (cal-tex-arg "$\\diamond$" )
  1156.        (cal-tex-e-makebox)
  1157.        (cal-tex-rule "0mm" "15.5cm" ".2mm")
  1158.        (cal-tex-nl ".2cm"))
  1159.     (cal-tex-hfill)
  1160.     (insert (cal-tex-mini-calendar
  1161.              (extract-calendar-month (cal-tex-previous-month date))
  1162.              (extract-calendar-year (cal-tex-previous-month date))
  1163.              "lastmonth" "1.1in" "1in"))
  1164.     (insert (cal-tex-mini-calendar
  1165.              (extract-calendar-month date)
  1166.              (extract-calendar-year date)
  1167.              "thismonth" "1.1in" "1in"))
  1168.     (insert (cal-tex-mini-calendar
  1169.              (extract-calendar-month (cal-tex-next-month date))
  1170.              (extract-calendar-year (cal-tex-next-month date))
  1171.              "nextmonth" "1.1in" "1in"))
  1172.     (insert "\\hbox to \\textwidth{")
  1173.     (cal-tex-hfill)
  1174.     (insert "\\lastmonth")
  1175.     (cal-tex-hfill)
  1176.     (insert "\\thismonth")
  1177.     (cal-tex-hfill)
  1178.     (insert "\\nextmonth")
  1179.     (cal-tex-hfill)
  1180.     (insert "}")
  1181.     (cal-tex-banner "end of cal-tex-daily-page")))
  1182. ;;;  Mini calendars
  1183. (defun cal-tex-mini-calendar (month year name width height &optional ptsize colsep)
  1184.   "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
  1185. Optional PTSIZE gives the point ptsize; scriptsize is the default.  Optional
  1186. COLSEP gives the column separation; 1mm is the default."
  1187.   (let* ((blank-days;; at start of month
  1188.           (mod
  1189.            (- (calendar-day-of-week (list month 1 year))
  1190.               calendar-week-start-day)
  1191.            7))
  1192.           (last (calendar-last-day-of-month month year))
  1193.          (colsep (if colsep colsep "1mm"))
  1194.          (str (concat "\\def\\" name "{\\hbox to" width "{%\n"
  1195.                       "\\vbox to" height "{%\n"
  1196.                       "\\vfil  \\hbox to" width "{%\n"
  1197.                       "\\hfil\\"
  1198.                       (if ptsize ptsize "scriptsize")
  1199.                       "\\begin{tabular}"
  1200.                       "{@{\\hspace{0mm}}r@{\\hspace{" colsep
  1201.                       "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
  1202.                       "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
  1203.                       "}}r@{\\hspace{" colsep "}}r@{\\hspace{0mm}}}%\n"
  1204.                       "\\multicolumn{7}{c}{"
  1205.                       (calendar-month-name month)
  1206.                       " "
  1207.                       (int-to-string year)
  1208.                       "}\\\\[1mm]\n")))
  1209.     (calendar-for-loop i from 0 to 6 do
  1210.       (setq str (concat str
  1211.                         (substring (aref calendar-day-name-array 
  1212.                                          (mod (+ calendar-week-start-day i) 7))
  1213.                                    0 2)
  1214.                         (if (/= i 6)
  1215.                             " & "
  1216.                           "\\\\[0.7mm]\n"))))
  1217.     (calendar-for-loop i from 1 to blank-days do
  1218.       (setq str (concat str " & ")))
  1219.     (calendar-for-loop i from 1 to last do
  1220.       (setq str (concat str (int-to-string i)))
  1221.       (setq str (concat str (if (zerop (mod (+ i blank-days) 7))
  1222.                                 (if (/= i last) "\\\\[0.5mm]\n" "")
  1223.                               " & "))))
  1224.     (setq str (concat str "\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
  1225.    str))
  1226. ;;;  Various calendar functions
  1227. (defun cal-tex-incr-date (date &optional n)
  1228.   "The date of the day following DATE.
  1229. If optional N is given, the date of N days after DATE."
  1230.   (calendar-gregorian-from-absolute
  1231.    (+ (if n n 1) (calendar-absolute-from-gregorian date))))
  1232. (defun cal-tex-latexify-list (date-list date &optional separator)
  1233.   "Return string with concatenated, LaTeXified entries in DATE_LIST for DATE.
  1234. Use double backslash as a separator unless optional SEPARATOR is given."
  1235.   (mapconcat '(lambda (x) (cal-tex-LaTeXify-string  x))
  1236.              (let ((result)
  1237.                    (p date-list))
  1238.                (while p
  1239.                  (and (car (car p))
  1240.                       (calendar-date-equal date (car (car p)))
  1241.                       (setq result (append (cdr (car p)) result)))
  1242.                  (setq p (cdr p)))
  1243.                result)
  1244.              (if separator separator "\\\\")))
  1245. (defun cal-tex-previous-month (date)
  1246.   "Return the date of the first day in the month previous to DATE."
  1247.   (let* ((month (extract-calendar-month date))
  1248.          (year (extract-calendar-year date)))
  1249.     (increment-calendar-month month year -1)
  1250.     (list month 1 year)))
  1251. (defun cal-tex-next-month (date)
  1252.   "Return the date of the first day in the  month following DATE."
  1253.   (let* ((month (extract-calendar-month date))
  1254.          (year (extract-calendar-year date)))
  1255.     (increment-calendar-month month year 1)
  1256.     (list month 1 year)))
  1257. ;;;  LaTeX Code
  1258. (defun cal-tex-end-document ()
  1259.   "Finish the LaTeX document.
  1260. Insert the trailer to LaTeX document, pop to LaTeX buffer, add 
  1261. informative header, and run HOOK."
  1262.   (cal-tex-e-document)
  1263.   (latex-mode)
  1264.   (pop-to-buffer cal-tex-buffer)
  1265.   (goto-char (point-min))    
  1266.   (cal-tex-comment "       This buffer was produced by cal-tex.el.")
  1267.   (cal-tex-comment "       To print a calendar, type")
  1268.   (cal-tex-comment "          M-x tex-buffer RET")
  1269.   (cal-tex-comment "          M-x tex-print  RET")
  1270.   (goto-char (point-min)))
  1271. (defun cal-tex-insert-preamble (weeks landscape size &optional append)
  1272.   "Initialize the output buffer.
  1273. Select the output buffer, and insert the preamble for a calendar of 
  1274. WEEKS weeks.  Insert code for landscape mode if LANDSCAPE is true. 
  1275. Use pointsize SIZE.  Optional argument APPEND, if t, means add to end of
  1276. without erasing current contents."
  1277.   (let ((width "18cm")
  1278.         (height "24cm"))
  1279.     (if landscape
  1280.         (progn
  1281.           (setq width "24cm")
  1282.           (setq height "18cm")))
  1283.     (if (not append)
  1284.         (progn
  1285.           (cal-tex-preamble size)
  1286.           (if (not landscape) 
  1287.             (progn
  1288.               (cal-tex-cmd "\\oddsidemargin -1.75cm")
  1289.               (cal-tex-cmd "\\def\\holidaymult{.06}"))
  1290.             (cal-tex-cmd "\\special{landscape}")
  1291.             (cal-tex-cmd "\\textwidth  9.5in")
  1292.             (cal-tex-cmd "\\textheight 7in")
  1293.             (cal-tex-comment)
  1294.             (cal-tex-cmd "\\def\\holidaymult{.08}"))
  1295.           (cal-tex-cmd  cal-tex-caldate)
  1296.           (cal-tex-cmd  cal-tex-myday)
  1297.           (cal-tex-b-document)
  1298.           (cal-tex-cmd "\\pagestyle{empty}")))
  1299.     (cal-tex-cmd "\\setlength{\\cellwidth}" width)
  1300.     (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
  1301.                     (/ 1.1 (length cal-tex-which-days))))
  1302.     (cal-tex-cmd "\\setlength{\\cellheight}" height)
  1303.     (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
  1304.                     (/ 1.0 weeks)))              
  1305.     (cal-tex-cmd "\\ \\par")
  1306.     (cal-tex-vspace "-3cm")))
  1307. (defvar cal-tex-LaTeX-subst-list
  1308.   '(("\"". "``")
  1309.     ("\"". "''");; Quote changes meaning when list is reversed.
  1310.     ("@" . "\\verb|@|") 
  1311.     ("&" . "\\&") 
  1312.     ("%" . "\\%") 
  1313.     ("$" . "\\$")
  1314.     ("#" . "\\#")
  1315.     ("_" . "\\_")
  1316.     ("{" . "\\{")
  1317.     ("}" . "\\}")
  1318.     ("<" . "$<$")
  1319.     (">" . "$>$")
  1320.     ("\n" . "\\ \\\\"))  ;\\ needed for e.g \begin{center}\n AA\end{center}
  1321.   "List of symbols and their replacements.")
  1322. (defun cal-tex-LaTeXify-string (string)
  1323.   "Protect special characters in STRING from LaTeX."
  1324.   (if (not string)
  1325.       ""
  1326.     (let ((head "")
  1327.           (tail string)
  1328.           (list cal-tex-LaTeX-subst-list))
  1329.       (while (not (string-equal tail ""))
  1330.         (let* ((ch (substring tail 0 1))
  1331.                (pair (assoc ch list)))
  1332.           (if (and pair (string-equal ch "\""))
  1333.               (setq list (reverse list)));; Quote changes meaning each time.
  1334.           (setq tail (substring tail 1))
  1335.           (setq head (concat head (if pair (cdr pair) ch)))))
  1336.       head)))
  1337. (defun cal-tex-hfill () "Insert hfill." (insert "\\hfill"))
  1338. (defun cal-tex-newpage () "Insert newpage." (insert "\\newpage%\n"))
  1339. (defun cal-tex-noindent () "Insert noindent." (insert "\\noindent"))
  1340. (defun cal-tex-vspace (space)
  1341.   "Insert vspace command to move SPACE vertically."
  1342.   (insert "\\vspace*{" space "}")
  1343.   (cal-tex-comment))
  1344. (defun cal-tex-hspace (space)
  1345.   "Insert hspace command to move SPACE horizontally."
  1346.   (insert "\\hspace*{" space "}")
  1347.   (cal-tex-comment))
  1348. (defun cal-tex-comment (&optional comment)
  1349.   "Insert % at end of line, include COMMENT if present, and move
  1350.    to next line."
  1351.   (insert "% ")
  1352.   (if comment
  1353.       (insert comment))
  1354.   (insert "\n"))
  1355. (defun cal-tex-banner (comment)
  1356.   "Insert the COMMENT separated by blank lines."
  1357.   (cal-tex-comment)
  1358.   (cal-tex-comment)
  1359.   (cal-tex-comment (concat "\t\t\t" comment))
  1360.   (cal-tex-comment))
  1361. (defun cal-tex-nl (&optional skip comment)
  1362.   "End a line with \\.  If SKIP, then add that much spacing.
  1363.    Add COMMENT if present"
  1364.   (insert "\\\\")       
  1365.   (if skip 
  1366.       (insert "[" skip "]"))
  1367.   (cal-tex-comment comment))
  1368. (defun cal-tex-arg (&optional text)
  1369.   "Insert optional TEXT surrounded by braces."
  1370.   (insert "{")
  1371.   (if text (insert text))
  1372.   (insert "}"))
  1373. (defun cal-tex-cmd (cmd &optional arg)
  1374.   "Insert LaTeX CMD, with optional ARG, and end with %"
  1375.   (insert cmd)
  1376.   (cal-tex-arg arg)
  1377.   (cal-tex-comment))
  1378. ;;;   Environments
  1379. (defun cal-tex-b-document ()
  1380.   "Insert beginning of document."
  1381.   (cal-tex-cmd "\\begin{document}"))
  1382. (defun cal-tex-e-document ()
  1383.   "Insert end of document."
  1384.   (cal-tex-cmd "\\end{document}"))
  1385. (defun cal-tex-b-center ()
  1386.   "Insert beginning of centered block."
  1387.   (cal-tex-cmd "\\begin{center}"))
  1388. (defun cal-tex-e-center ()
  1389.   "Insert end of centered block."
  1390.   (cal-tex-comment)
  1391.   (cal-tex-cmd "\\end{center}"))
  1392. ;;;  Boxes
  1393. (defun cal-tex-b-parbox (position width)
  1394.   "Insert parbox with parameters POSITION and WIDTH."
  1395.   (insert "\\parbox[" position "]{" width "}{")
  1396.   (cal-tex-comment))
  1397. (defun cal-tex-e-parbox (&optional height)
  1398.   "Insert end of parbox. Force it to be a given HEIGHT."
  1399.   (cal-tex-comment)
  1400.   (if height
  1401.       (cal-tex-rule "0mm" "0mm" height))
  1402.   (insert "}")
  1403.   (cal-tex-comment "end parbox"))
  1404. (defun cal-tex-b-framebox ( width position )
  1405.   "Insert  framebox with parameters WIDTH and POSITION (clr)."
  1406.   (insert "\\framebox[" width "][" position "]{" )
  1407.   (cal-tex-comment))
  1408. (defun cal-tex-e-framebox ()
  1409.   "Insert end of framebox."
  1410.   (cal-tex-comment)
  1411.   (insert "}")
  1412.   (cal-tex-comment "end framebox"))
  1413. (defun cal-tex-b-makebox ( width position )
  1414.   "Insert  makebox with parameters WIDTH and POSITION (clr)."
  1415.   (insert "\\makebox[" width "][" position "]{" )
  1416.   (cal-tex-comment))
  1417. (defun cal-tex-e-makebox ()
  1418.   "Insert end of makebox."
  1419.   (cal-tex-comment)
  1420.   (insert "}")
  1421.   (cal-tex-comment "end makebox"))
  1422. (defun cal-tex-rule (lower width height)
  1423.   "Insert a rule with parameters LOWER WIDTH HEIGHT."
  1424.   (insert "\\rule[" lower "]{" width "}{" height "}"))
  1425. ;;;     Fonts
  1426. (defun cal-tex-em (string)
  1427.   "Insert STRING in bf font."
  1428.   (insert "{\\em " string "}"))
  1429. (defun cal-tex-bf (string)
  1430.   "Insert STRING in bf font."
  1431.   (insert "{\\bf " string "}"))
  1432. (defun cal-tex-scriptsize (string)
  1433.   "Insert STRING in scriptsize font."
  1434.   (insert "{\\scriptsize " string "}"))
  1435. (defun cal-tex-huge (string)
  1436.   "Insert STRING in huge size."
  1437.   (insert "{\\huge " string "}"))
  1438. (defun cal-tex-Huge (string)
  1439.   "Insert STRING in Huge size."
  1440.   (insert "{\\Huge " string "}"))
  1441. (defun cal-tex-Huge-bf (string)
  1442.   "Insert STRING in Huge bf size."
  1443.   (insert "{\\Huge\\bf " string "}"))
  1444. (defun cal-tex-large (string)
  1445.   "Insert STRING in large size."
  1446.   (insert "{\\large " string "}"))
  1447. (defun cal-tex-large-bf (string)
  1448.   "Insert STRING in large bf size."
  1449.   (insert "{\\large\\bf  " string "}"))
  1450. (provide 'cal-tex)
  1451. ;;; cal-tex.el ends here
  1452.